<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <div class="tabs">
      <el-tabs class="demo-tabs" stretch v-model="activeName">
        <el-tab-pane name="account" label="账号登录">
          <template #label>
            <div class="label">
              <el-icon><User /></el-icon>
              <span class="text">账号登录</span>
            </div>
          </template>
          <pane-account ref="accountRef" />
        </el-tab-pane>

        <el-tab-pane name="phone" label="手机登录">
          <template #label>
            <div class="label">
              <el-icon><Iphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <pane-phone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button
      class="login-btn"
      type="primary"
      size="large"
      @click="handleLoginBtbClick"
      >立即登录</el-button
    >
  </div>
</template>
  
<script lang="ts" setup>
import { localCache } from '@/utils/cache'
import type PaneAccount from './pane-account.vue'
import paneAccount from './pane-account.vue'
import panePhone from './pane-phone.vue'
import { ref, watch } from 'vue'

//创建子组件实例对象
const accountRef = ref<InstanceType<typeof PaneAccount>>()

const activeName = ref('account')
//记住密码状态
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
watch(isRemPwd, (newVal) => {
  localCache.setCache('isRemPwd', newVal)
})
function handleLoginBtbClick() {
  // 判断当前的激活名称是否为 'account'
  if (activeName.value === 'account') {
    // 如果是 'account'，则调用 accountRef 的 loginAction 方法，将账号密码存入本地
    accountRef.value?.loginAction(isRemPwd.value)
  } else {
    // 否则，输出 '手机登录'
    console.log('手机登录')
  }
}
</script>
  
<style lang="less" scoped>
.login-panel {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
    margin-bottom: 15px;
  }

  .label {
    display: flex;
    align-items: center;
    justify-content: center;

    .text {
      margin-left: 5px;
    }
  }

  .controls {
    margin-top: 12px;
    display: flex;

    justify-content: space-between;
  }

  .login-btn {
    margin-top: 10px;
    width: 100%;
    // --el-button-size: 50px;
  }
}
</style>